Compilation
Compilation of the C Interface libdivERGe.so.
Minimal Requirements
up-to-date C/C++ compiler (that can handle c++17 and c11)
a BLAS and LAPACK implementation including the CBLAS and LAPACKE interfaces
FFTW3, including its parallel (OpenMP or (p)threads) version
a linux machine is favorable (WSL ‘just works’, MacOS with some tweaks)
Make
To compile the library, navigate into the diverge directory (the git repo’s root) and execute make:
cd /path/to/diverge/
make -jXX
This will compile the C Interface with XX threads in parallel. For installation of the python library (see Simulation Output and Python Interface), execute
pip install .
in the git repo’s root. Note that you might want to create a virtual environment first, or change the above pip call to
pip install --editable . --config-settings editable_mode=strict --break-system-packages
The makefile exposes several targets to build specific components of divERGe:
Target |
Effect |
|---|---|
|
build the library, specifically, libdivERGe.so. |
|
build an executable (divERGe) that does nothing but running
|
|
pack the divERGe.tgz file with the shared library, header files, python library, and examples |
|
remove all build time files (object files .o, dependency files .d, …) |
Changing the defaults
To compile the code with different options/compiler/etc., you can create a file ‘Makefile.local’ in the top level directory of the git repository. This file is sourced by the Makefile and therefore allows for full control.
To add, e.g., the non-standard FFTW3 path /opt/fftw/ to the include and link locations, put
INCLUDES += -I/opt/fftw/include/
LIBS += -L/opt/fftw/lib/
into the ‘Makefile.local’ (this is an example, actual content will differ!)
Examples for Makefile.local
The make.local/ directory of the git repo contains various examples of how to compile divERGe on certain machines/configurations.
Variables defined and used in ‘Makefile’
Compilers etc.
CC := gcc # C compiler
LD := g++ # linker
CXX := g++ # C++ compiler
CUCC := nvcc # CUDA compiler, only used when USE_CUDA := true
AR := ar # if you don't know this you don't need to change it
STRIP := strip # if you don't know this you don't need to change it
usual suspects
PREFLAGS = # flags that should come before anything else in CFLAGS/CXXFLAGS
INCLUDES = # additional -I/some/where/ to find library headers
DEFINES = # additional -DSOME_THING to play with features
LIBS = -llapacke -lcblas -lfftw3 -lfftw3_omp # libraries
MPI Compilation
in your ‘Makefile.local’, put
DEFINES += -DUSE_MPI
CC := mpicc
CXX := mpicxx
LD := mpicxx
Further optimizations for MPI parallelism can be enabled, they are toggled via
DEFINE keys (i.e. adding DEFINES += -DKEY to Makefile.local, see
Compilation DEFINES for a full list). MPI related Compilation DEFINES are, in addition, listed here:
Compilation DEFINE |
Explanation |
|---|---|
|
experimental support for putting some objects
(Hamiltonian, Orbital/Band matrices) into
node-global shared memory,
i.e., creating a shared memory pool that is used by
all MPI ranks on a single node. This flag requires some
more recent linux kernel features ( |
|
use the MPI backend for FFTW in the TU propagator calculation. this usually comes with an enormeous speedup |
|
be extra verbose on TU propagator allocations in the new CPU MPI algorithm |
|
try to optimize memory access and usage by defining some tensors in different ordering. Only enabled when switching the (undocumented) tu_which_fft_{greens,simple,red} to the old MPI FFT algorithm (see below…) |
Some other experimental (UNSUPPORTED) MPI-related features are not enabled at
compile time but rather at runtime; and steered using
diverge_model_hack(). This includes the following config keys:
Config Key |
Explanation |
|---|---|
|
swap the FFT algorithm for Green’s function generation in the TU propagator (int values see enumeration in source) |
|
swap the FFT algorithm for the simple TU propagator generation |
|
swap the FFT algorithm for the reduced TU propagator generation |
|
put the Green’s function in node-global shared memory and
overwrite the |
|
free the hamiltonian array s.t. it doesn’t consume valuable RAM. Most meaningful when, again, using many ranks. |
|
if !0, enable verbose timing of the (CPU/MPI) algorithms in the TU propagator |
|
set the number of FFTs executed in parallel in the CPU/MPI
algorithm of the TU propagator to the given value; default is
the value of |
CUDA Compilation
in your ‘Makefile.local’, put
USE_CUDA := true
depending on your infrastructure, you might need to adjust CULIBS and
INCLUDES to allow for finding the CUDA libraries and inclusion of the right
headers. Examples are found in the make.local/ directory of the git
repo.
Compiling Tests
The production builds usually include divERGe’s test suite (based on catch2.hpp). If you wish to get an executable usable to run the tests, compile using
make test -j
To run the tests call the executable from the command line with
./divERGe
Advanced Compilation Features
C/C++/CUDA flags are usually not changed manually, but still exposed through the Makefile.local like this:
# usually no need to change directly
CXXFLAGS = $(PREFLAGS) -std=c++17 -fPIC -fopenmp -MMD -Wall -Wextra -pedantic $(DEFINES) $(INCLUDES)
CFLAGS = $(PREFLAGS) -std=c11 -fPIC -fopenmp -MMD -Wall -Wextra -pedantic $(DEFINES) $(INCLUDES)
LDFLAGS = -fPIC -fopenmp -Wall -Wextra -pedantic $(LIBS)
CUFLAGS = $(DEFINES) $(INCLUDES) $(DEVICES) -Xcompiler="-fPIC -fopenmp" -rdc=true
CULDFLAGS = -Xcompiler="-fPIC"
Cuda libraries and device configuration options are set in the Makefile.local like:
CULIBS = -lcudart -lcuda -lcufft -lcublas -lcusolver -lcusolverMg
DEVICES = -gencode arch=compute_70,code=sm_70 \
-gencode arch=compute_75,code=sm_75 \
-gencode arch=compute_80,code=sm_80
Advanced linker options for both the library libdivERGe.so as well as the testing executable divERGe can be set through:
# for linkage:
# EXEFLAGS: linking of the main executable
# SOFLAGS: linking of the library
# LDSOFLAGS: LDFLAGS used for linking of the library
EXEFLAGS =
SOFLAGS = -Wl,--version-script=libdivERGe.map -shared
LDSOFLAGS = $(LDFLAGS)
Compilation DEFINES
Various features are enabled/disabled using compile-time flags (“DEFINES”). Those mostly enable experimental, untested, or deprecated features. In general, there exist compile time variables that toggle behavior when defined and other ones that may carry a value. In the former case, you can extend the Makefile.local with
DEFINES += -DVARIABLE_NAME
to have the variable VARIABLE_NAME defined. In the latter case, use
DEFINES += -DVARIABLE_NAME=VARIABLE_VAL
which sets the variable VARIABLE_NAME to VARIABLE_VAL. An incomplete
list of compile time variables is given below, where either only the name is
written (i.e., the variable can be either defined or not), or
VARIABLE_NAME=VARIABLE_VAL including an explanation (in which case the
value of the variable VARIABLE_VAL has an effect).
Compilation DEFINE |
Explanation |
|---|---|
|
set default number of chunks in GPU batched eigensolver to NUM |
|
set maximum size of chunk in GB for GPU batched eigensolver to GB |
|
compile all batched GEMMs where the matrix dimension is (much) smaller than the number of executions up to matrix size VAL explicitly. default: 4. |
|
use this function name for batched cublas gemm instead of the default “cublasZgemmStridedBatched_64” (may not be there in older CUDA versions) |
|
on old CUDA versions, constexpr may not be supported. define to circumvent this issue. |
|
on old CUDA versions (or when compiling for old GPU architectures) atomicAdd is not defined. defining this variable adds an implementation (that is usually slower than the actual one on recent hardware) |
|
set the CUDA version string to VAL (used in release builds) |
|
set the difference at which two momentum mesh points are considered to be equal |
|
if defined, do the grid FRG batched GEMM in parallel |
|
integer constant that defines how to select arpack backend in |
|
integer constant that sets the default number of maximum iterations in the power iteration
backend of |
|
floating point constant that sets the default tolerance for power iteration backend of
|
|
if defined, do not use fancy colors in the log messages, but only bright white |
|
if defined, use grayscale instead of fancy colors in the log messages. cleaner, more modern look |
|
do not print the log names |
|
set the log prefix to VAL |
|
change the magic number for the output files generated by |
|
change the default number of band structure points per segment to VAL |
|
if defined, diverge will not abort the program upon encountering a CUDA error. |
|
if defined, color escape sequences are not removed from the output even if it may be redirected to a file |
|
limit the number of threads to be used in OpenBLAS calls to VAL. useful when the OpenBLAS library is compiled for a certain maximum number of threads that can be exceeded by modern cluster architectures. |
|
use LAPACK’s |
|
some MKL versions define |
|
limit the number of threads in |
|
set the maximum number of characters in a line parsed with the (internal) text_io.h parser |
|
do not compile |
|
disable compiler optimizations for IEEE 754 Quiet NaN, may be needed for |
|
enable in-place permutation algorithm for TU projection initialization by default (slower, deprecated) |
|
set the coarsification of the Green’s function to happen via FFTs (in the selfenergy kernel). |
|
set the default algorithm for finding unique orbital/formfactor combinations to an O(1) one which relies on a custom hashtable implementation (splitmix64) |
|
use the U-matrix of the SVD instead of the V-matrix for vertex diagonalization in TU post |
|
enable fine projection timing in TU |
|
use |
|
set the maximum number of bands considered in a single CUDA thread for the LDOS GPU kernels |
|
set the number of threads per block to use in the LDOS GPU kernels |
|
the ctest.h library relies on the compiler’s ability to add startup code to C functions (non-standard). This can be circumvented by defining the initializer skip. Note that most reasonable compilers (gcc, clang, …) support initializer code, though. |
|
provide a declaration of the |
|
set the git version string to VAL |
|
set the git branch string to VAL |
|
set the maximum distance of formfactors to be generated in the grid FRG code to VAL |
|
do not turn off Eigen optimizations. They are nice in general, but do not allow to operate on the underlying memory transparently. Thus they are turned off by default. |
|
set the grid FRG post processing magic number to VAL |
|
set the npatch FRG post processing magic number to VAL |
|
define the maximum length of the character array holding |
|
define the maximum number of orbitals to be used in |
|
define the maximum length of symmetry arrays being used in |
|
define the maximum number of orbitals on a single site used in |
|
set the maximum number of CUDA threads in a CUDA block for the npatch GPU kernels |
|
if defined explicitly force MKL to use AVX kernels on AMD EPYC CPUs. Might improve performance (MAYBE OUTDATED) |
|
standard DEFINE that has some implications in divERGe as well (smaller messages, …) |
|
skip file and line information in error messages |
|
define VAL that is seen to be zero for floating point comparisons in the npatch code |
|
for momentum additions/subtractions that extend over more than one primitive zone, define the range in G vectors that is searched |
|
some clusters install eigen3 in a way equivalent to /usr/include/Eigen instead of /usr/include/eigen3/Eigen. This flag is there to enable the former. |
|
do not time the flow step in the grid FRG code |
|
set the git tag version string to VAL |
|
set the TU backend post processing magic number (relevant for output) to VAL |
|
compile an ARPACK-based eigensolver that can be used for |
|
compress the output files using Zstandard. Linkage to |
|
use |
|
in the parallel mergesort implementation shipped with divERGe set the default serial task size
to |
|
use an alternative method of measuring time when compiling without MPI |
|
use Eigen’s matrix multiplication in batched gemms (CPU) |
|
default to a CPU version of the batched eigensolver, built with Eigen3. Can be turned off at run
time via |
|
compile extensive fixed-size versions (up to dimension |
|
save Green’s function in single point precision. should work for the npatch backend. |
|
use |
|
enable MPI parallelization (MPI Compilation). Not recommended in conjunction with GPUs (CUDA Compilation) as GPU/MPI algorithms are scarcely available and therefore not implemented. |
|
in the vertex/loop batched GEMMs of the grid FRG code, skip BLAS calls and do the multiplication by hand. |
|
do not use LAPACK functions (or, their C wrappers) but Eigen. |
|
do not enable multithreaded FFTW. |
|
experimental support for putting some objects (Hamiltonian, Orbital/Band matrices) into
node-global shared memory, i.e., creating a shared memory pool that is used by all MPI ranks on a
single node. This flag requires some more recent linux kernel features ( |
|
use |
|
use the POSIX functions |
|
use a syscall to |
|
use the MPI backend for FFTW in the TU propagator calculation. this usually comes with an enormeous speedup. Users are responsible for adding the corresponding linker flags to the Makefile.local. |
|
set the MPI packing size to |
|
be verbose in TU GPU/MPI kernels about memory allocations. |
|
algin host memory in TU propagator kernels to |
|
be extra verbose on TU propagator allocations in the new CPU/MPI algorithms |
|
try to optimize memory access and usage by defining some tensors in different ordering. Only
enabled when switching the TU propagator algorithms via |